
import NativeMgr from "../../../../general/Script/mgr/nativeManager";
import NetMgr, { g_rankType } from "../../../../general/Script/mgr/netManager";
import { subGameMgr } from "../../../../general/Script/mgr/SubGameMgr";
import ExtendButton from "../../common/extend/ExtendButton";
import DataManager from "../../common/important/DataManager";
import LayerBase from "../../expand/ui/LayerBase";
import GameSnake from "../GameSnake";
import { SceneType } from "./scene/SceneType";

const { ccclass, property } = cc._decorator;
@ccclass
export default class LayerGameOver extends LayerBase {
    @property(cc.Label)
    public LabelNowScore: cc.Label = null;
    @property(cc.Label)
    public LabelBestScore: cc.Label = null;

    @property(cc.Button)
    public ButtonReplay: cc.Button = null;
    @property(cc.Button)
    public ButtonBack: cc.Button = null;
    public init(): boolean {
        ExtendButton.AddOnClick(this.ButtonReplay, this.onClickReplay, this);
        ExtendButton.AddOnClick(this.ButtonBack, this.onClickBack, this);
        let scale1 = cc.scaleTo(0.3, 1.1);
        let scale2 = cc.scaleTo(0.3, 0.9);
        this.ButtonReplay.node.runAction(cc.repeatForever(cc.sequence(scale1, scale2)));
        return true;
    }

    public onClickReplay(): void {
        cc.director.loadScene(SceneType.GameScene.toString());
    }


    onClickBack() {
        NativeMgr.Ins().showFullAds();

        cc.director.loadScene("home");
        subGameMgr.exitSubGame();
    }


    public initOver(snake: GameSnake) {
        let score = DataManager.Score;
        this.LabelNowScore.string = snake.Score.toString();
        this.LabelBestScore.string = "Best:" + score;
        NetMgr.Ins().postRankList(g_rankType.snake, score);
    }
}
